package com.ruoyi.custom.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.custom.domain.StoreProductRule;
import com.ruoyi.custom.service.IStoreProductRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品规则值(规格)Controller
 * 
 * @author xking
 * @date 2022-08-03
 */
@RestController
@RequestMapping("/custom/rule")
public class StoreProductRuleController extends BaseController
{
    @Autowired
    private IStoreProductRuleService storeProductRuleService;

    /**
     * 查询商品规则值(规格)列表
     */
    @GetMapping("/listRuleSelect")
    public TableDataInfo listRuleSelect()
    {
        List<StoreProductRule> list = storeProductRuleService.selectStoreProductRuleList(null);
        return getDataTable(list);
    }


    /**
     * 查询商品规则值(规格)列表
     */
    @PreAuthorize("@ss.hasPermi('custom:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(StoreProductRule storeProductRule)
    {
        startPage();
        List<StoreProductRule> list = storeProductRuleService.selectStoreProductRuleList(storeProductRule);
        return getDataTable(list);
    }

    /**
     * 导出商品规则值(规格)列表
     */
    @PreAuthorize("@ss.hasPermi('custom:rule:export')")
    @Log(title = "商品规则值(规格)", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StoreProductRule storeProductRule)
    {
        List<StoreProductRule> list = storeProductRuleService.selectStoreProductRuleList(storeProductRule);
        ExcelUtil<StoreProductRule> util = new ExcelUtil<StoreProductRule>(StoreProductRule.class);
        util.exportExcel(response, list, "商品规则值(规格)数据");
    }

    /**
     * 获取商品规则值(规格)详细信息
     */
    @PreAuthorize("@ss.hasPermi('custom:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(storeProductRuleService.selectStoreProductRuleById(id));
    }

    /**
     * 新增商品规则值(规格)
     */
    @PreAuthorize("@ss.hasPermi('custom:rule:add')")
    @Log(title = "商品规则值(规格)", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StoreProductRule storeProductRule)
    {
        return toAjax(storeProductRuleService.insertStoreProductRule(storeProductRule));
    }

    /**
     * 修改商品规则值(规格)
     */
    @PreAuthorize("@ss.hasPermi('custom:rule:edit')")
    @Log(title = "商品规则值(规格)", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StoreProductRule storeProductRule)
    {
        return toAjax(storeProductRuleService.updateStoreProductRule(storeProductRule));
    }

    /**
     * 删除商品规则值(规格)
     */
    @PreAuthorize("@ss.hasPermi('custom:rule:remove')")
    @Log(title = "商品规则值(规格)", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(storeProductRuleService.deleteStoreProductRuleByIds(ids));
    }
}
